package com.example.controller;

import com.example.common.Result;
import com.example.pojo.entity.Museum;
import com.example.pojo.entity.Museum;
import com.example.pojo.entity.User;
import com.example.service.MuseumService;
import com.example.service.MuseumService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/museum")
public class MuseumController {

    @Resource
    MuseumService museumService;

    @PostMapping("/add")
    public Result add(@RequestBody Museum museum) {
        museumService.insert(museum);
        return Result.success();
    }

    /*
      修改用户
     */
    @PutMapping("/update")
    public Result update(@RequestBody Museum museum){
        museumService.updateById(museum);
        return Result.success();
    }


    /*
         删除用户
         */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        museumService.removeById(id);
        return Result.success();
    }



    //批量删除用户

    @DeleteMapping("/delete/batch")
    public Result batchDelete(@RequestBody List<Integer> ids){
        museumService.removeBatchByIds(ids);
        return Result.success();
    }



    //根据ID查询用户

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        Museum museum = museumService.getById(id);
        return Result.success(museum);
    }


    // 分页查询用户

    @GetMapping("/selectByPage")
    public Result selectByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String name) {
        PageInfo<Museum> pageInfo = museumService.selectByPage(pageNum, pageSize, name);
        return Result.success(pageInfo);
    }
}

